<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['user']['tab'], 'finance');?>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-2 m-b-sm">
		<select id="srchtype" value="<?php echo $srchtype; ?>" class="form-control">
			<option value="username" <?php if($srchtype=='username'){echo 'selected';}?>>用户名</option>
		</select>
	</div>
	<div class="col-md-2 m-b-sm">
		<input type="text" id="keyword" placeholder="关键字" value="<?php echo $keyword; ?>"  class="form-control" />
	</div>
	<div class="col-md-2 m-b-sm">
		<button id="search" class="form-control btn btn-primary">搜索财务</button>
	</div>
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">删除</th>
							<th class="text-center">用户名</th>
							<th class="text-center">登录IP</th>
							<th class="text-center">登录时间</th>
							<th class="text-center">操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
						<?php if($users){foreach($users as $_user){ ?>
						<tr uid="<?php echo $_user['uid']; ?>">
							<td class="text-center"><input type="checkbox" name="delete" /></td>
							<td class="text-center"><?php echo $_user['username']; ?></td>
							<td class="text-center"><?php echo $_user['login_ip']; ?></td>
							<td class="text-center"><?php echo $_user['login_time']?date('m-d H:i',$_user['login_time']):''; ?></td>
							<td class="text-center">
								<a href="<?php echo url("user-financeupdate-$_user[uid]"); ?>">编辑</a>
							</td>
						</tr>
						<?php }} ?>
					</tbody>
				</table>
			</div>
			<hr class="m-t-0" />
			<div class="row" style="margin:5px 10px;">
				<div class="col-lg-1">
					<div class="form-group">
						<input type="button" class="btn btn-warning" id="confirm" value="删除">
					</div>
				</div>
				<div class="col-lg-1">
					<div class="form-group">
						<a class="btn btn-primary active" href="user-financeadd.htm">添加财务</a>
					</div>
				</div>
			</div>
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>


<script>
//搜索
var jsearch = $("#search");
var jsrchtype = $("#srchtype");
var jkeyword = $('#keyword');
jsearch.on('click', function(){
	var srchtype = jsrchtype.val();
	srchtype = srchtype ? srchtype : 'uid';
	var keyword = $("#keyword").val();
	var url = xn.url('user-finance-'+srchtype+'-'+keyword+'-1');
	window.location = url;
});
jkeyword.on('keydown', function(e) {
	if(e.keyCode == 13) jsearch.trigger('click');
});

// 删除选中的用户
var jconfirm = $("#confirm");
var juserlist = $('#userlist');
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的财务");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		$.xpost(xn.url('user-financedel'), {uid:uid}, function(code, message) {
			if(code != 0) return $.alert(message);
			jtr.remove();
		});
	});
});


$('#nav_pc li.user, #nav_mobile li.user').tab('show');
</script>